package peer.dstdb;

import java.net.InetAddress;
import java.util.HashMap;
import java.util.Iterator;

public class LanGroup {
	InetAddress lanIp;
	HashMap<Integer, SourceNode> sourceNodeTable;
	LanGroup(InetAddress lanIp){
		this.lanIp=lanIp;
		sourceNodeTable=new HashMap<Integer, SourceNode>();
	}
	
	void addSourceNode(SourceNode sn){
		sourceNodeTable.put(sn.sourceSessionId, sn);
	}
	
	void removeSourceNode(int sourceSessionId){
		sourceNodeTable.remove(sourceSessionId);
	}
	
	void getLanSource(short blockNum,HashMap<Integer, SourceNode> hm){
		Iterator it=sourceNodeTable.keySet().iterator();
		while(it.hasNext()){
			int sourceSessionId=(Integer)it.next();
			SourceNode sn=sourceNodeTable.get(sourceSessionId);
			if(sn.containsBlock(blockNum)){
				hm.put(sourceSessionId, sn);
			}
			if(hm.size()==100){
				return;
			}
		}
	}

}
